<?php defined( 'BASEPATH' ) or die( 'Restricted' );

/*
This code is copyright 2009-2010 by TMLA INC.  ALL RIGHTS RESERVED.
Please view license.txt in /tgsf_core/legal/license.txt or
http://tgWebSolutions.com/opensource/tgsf/license.txt
for complete licensing information.
*/

if ( GET()->exists( 'm' ) )
{
	load_config( 'messages' );
	$messages = config( 'messages' );
	?><div class="msgbox"><span></span><?= $messages[GET()->m]; ?></div><?
}

?><div id="ajax-msg" class="msgbox"></div><?

$prevText = '&laquo; Prev';
$nextText = 'Next &raquo;';
$prevAllowed = $query->curPage > 1;

$nextAllowed = $query->curPage < $query->totalPages;

?><div class="top_nav">
	<?= $prevAllowed?$prev->anchorTag( $prevText ):$prevText; ?> |
	<?= $nextAllowed?$next->anchorTag( $nextText ):$nextText; ?> |
	<?= URL( 'new' )->anchorTag( 'Add/Update Link' )->id( 'add-link' ); ?>
</div>

<ul class="home-list">
<? foreach( $rows as $row ) : ?>
<li link_id="<?= $row->link_id; ?>" class="link <?= alternate( 'e', 'o' ); ?>">
	<?
	echo URL( 'l' )->setVar( 'ink', $row->link_id )->anchorTag( $row->link_page_title );
	$tag = $linkTagModel->fetchForLink( $row->link_id );
	$tags = array();
	$tagCnt = 0;
	while ( $tag->fetch() && $tagCnt < 20 )
	{
		$tagCnt++;
		$tags[] = URL( 't' )->setVar( 'ag', trim( $tag->tag_text ) )->anchorTag( $tag->tag_text );
	}
	if ( count( $tags ) )
	{
		?><div class="tags"><?= implode( $tags,', ' ); ?></div><?
	}
	?>
	<ul class="link-meta">
		<li><?= nl2br( $row->link_desc ); ?></li>
		<li><a href="<?= $row->link_url; ?>"><?= $row->link_url; ?></a></li>
		<li>added/updated: <?= $row->link_ts; ?></li>
		<li>popularity: <?= $row->link_add_count?> / <a class="spamlink" link_id="<?= $row->link_id; ?>" href="#">flag spam</a> : <span class="spam_count"><?= $row->link_spam_report_count; ?></span>
		<div class="clearspacer"></div>
		</li>
	</ul>
</li>
<? endforeach; ?>
</ul>

<div class="bottom_nav">
<?= $prevAllowed?$prev->anchorTag( $prevText ):$prevText; ?> |
<?= $nextAllowed?$next->anchorTag( $nextText ):$nextText; ?> |
<?= URL( 'new' )->anchorTag( 'Add New Link' ); ?>
</div>